<?php
class ControllerCommonCheckinform extends Controller {   
public function index(){
    $this->load->model('catalog/information');
    $this->template = 'common/checkinform.tpl';
	if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . 'common/checkinform.tpl')) {
        $this->template = $this->config->get('config_template') . 'common/checkinform.tpl';
    } 
	else 
	{
		$this->template = 'common/checkinform.tpl';
    }
	$this->load->model('catalog/checkingform');
	$this->load->model('localisation/zone');
	$state=$this->model_localisation_zone->getZonesByCountryId(99);
	$this->data['state'] = $state;
	$country=$this->model_catalog_checkingform->detailsCountry();
	$this->data['country'] = $country;
	$this->data['cancelUrl'] = $this->url->link('common/viewlist', 'token=' . $this->session->data['token'], 'SSL');
	$this->data['token'] = $this->session->data['token'];
	
	if($_GET['view']==1){
	 $uid=base64_decode($_GET['uid']);
		$this->load->model('catalog/checkingform');
		$userdetailes=$this->model_catalog_checkingform->userDetails($uid);
		$this->data['userdetailes'] = $userdetailes;
		$this->data['regurl']=$this->url->link('common/checkinform', 'token=' . $this->session->data['token'], 'SSL');	
		$this->data['userid'] = $uid;
		$this->template = 'common/viewuserdetailes.tpl';
		//echo '<pre>'; print_r($userdetailes); exit;
	}
	if($_POST) {
		if(($_POST['hidUid']!='')&&($_FILES['file']['name']!='')) 
		{
			$file = str_replace(' ', '_', $_FILES['file']['name']);
			move_uploaded_file($_FILES['file']['tmp_name'], DIR_IMAGE.'userimages/'.$file);
			$this->load->model('catalog/checkingform');
			$userid=$this->model_catalog_checkingform->updateUser($this->request->post,$file);
			$this->redirect($this->url->link('common/viewlist', 'token=' . $this->session->data['token'], 'SSL'));
		} 
		else if(($_POST['hidUid']!='')&&($_FILES['file']['name']==''))
		{
			$file=$_POST['image'];
			$this->load->model('catalog/checkingform');
			$userid=$this->model_catalog_checkingform->updateUser($this->request->post,$file);
			$this->redirect($this->url->link('common/viewlist', 'token=' . $this->session->data['token'], 'SSL'));
		}
		else 
		{
			//echo '<pre>'; print_r($_POST); exit;
			$file = str_replace(' ', '_', $_FILES['file']['name']);
			move_uploaded_file($_FILES['file']['tmp_name'], DIR_IMAGE.'userimages/'.$file);
			$this->load->model('catalog/checkingform');
			$userid=$this->model_catalog_checkingform->addUser($this->request->post,$file);
			$this->redirect($this->url->link('common/viewlist', 'token=' . $this->session->data['token'], 'SSL'));
		}
	}
	if($_GET['edit']== 1)
	{
		$uid=base64_decode($_GET['uid']);
		$this->load->model('catalog/checkingform');
		$userdetailes=$this->model_catalog_checkingform->userDetails($uid);
		$this->data['userdetailes'] = $userdetailes;
		$this->data['uid'] = base64_encode($uid);
	}
	else
	{
		$this->data['uid'] = '';
	}
	$this->children = array(
            'common/header',
            'common/footer'
    );      
    $this->response->setOutput($this->render());
  }
}
?>